<?php
/**
 * Resource for creating database adapter
 */
class BRail_Application_Resource_Db extends Zend_Application_Resource_Db
{
    /**
     * Initialize the Db Resource
     *
     * Initialize the Db Resourcethen, add profiler, and associate that adapter to Zend_Db
     *
     * @return Zend_Db_Adapter_Abstract|null
     */
    public function init()
    {
        $db = parent::init();

        // Register Auth plugin, as we need to give it the $acl
        // we can't rely on pure Zend_Application_Resource_Frontcontroller / config only
        $cache = $this->getBootstrap()->getResource('cache');

        // Setup the database profiling if needed
        $options = $this->getOptions();
        if (array_key_exists('profiler_firebug', $options) && $options['profiler_firebug']) {
            $profiler = new Zend_Db_Profiler_Firebug();
            $profiler->setEnabled(true);
            $db->setProfiler($profiler);
        }

        Zend_Db_Table_Abstract::setDefaultAdapter($db);

        return $db;
    }
}